<template>
    <div>
        <van-list v-model="loading" :finished="finished" :loading-text="$t('Loading')" :finished-text="$t('noMore')" offset='50' :error.sync="error" :error-text="$t('errorAndReload')" @load="onLoad">
            <div class="cart-box" v-for='item of dataList' :key='item.id'>
                <div class="head-box">{{item.firmName}}</div>
                <div class="titRow">{{item.type==3?$t('Agent'):$t('Installer')}} <span>|</span> {{item.optFlag == 0? $t('Unauthorized'):$t('Authorized')}}</div>
                <div class="titRow">{{$t('Contactperson')}} : {{item.relation | ifNull}}</div>
                <div class="titRow">{{$t('Phone')}} : {{item.telphone | ifNull}}</div>
                <div class="titRow">{{$t('Email')}} : {{item.email | ifNull}}</div>
                <div class="titRow">{{$t('CommisionDate')}} : {{item.createTimeStr}}</div>
            </div>
        </van-list>
    </div>
</template>

<script>
export default {
    props: {
        search:{
            type:String
        }
    },
    data() {
        return {
            dataList:[],
            loading:false,
            finished:false,
            current:1,
            error:false
        };
    },
    methods: {
        replay(val){
            this.current = 1;
            this.dataList = [];
            this.getAgentPage(val);
        },
        async getAgentPage(val){
            this.comm.loadingShow();
            let {result:res} = await this.API.getAgentPage(localStorage.getItem("domain"),{
                tokenId:localStorage.getItem("tokenId"),
                current:this.current,
                size: 10,
                firmName:val
            });
            this.dataList = [...this.dataList,...res.rows];
            this.loading = false;
            if((this.current-1)*10 > res.total){
                this.finished = true;
            }else{
                this.finished = false;
            }
            this.current++;
        },
        onLoad(){
            this.getAgentPage(this.search).catch(()=>{
                this.loading = false;
                this.error=true;
            });
        }
    },
};
</script>

<style  lang="less" scoped>
.cart-box{
    padding: 10px;
    background-color: #fff;
    margin-top: 15px;
    text-align: left;
    .head-box{
        border-bottom: 1px solid #e6e6e6;
        font-weight: 900;
        padding:0 0 8px 0px;
        overflow: hidden;
    }
    .titRow{
        width: 100%;
        margin-top: 6px;
        font-size: 15px;
        span{
            color: #d6d6d6;
        }
    }
}
</style>
